package five.itcast.cn;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

//程序入口Activity
public class MainActivity extends Activity {
    
	private Chessboard gameView;
	private final static int ITEM0=Menu.FIRST;
	private final static int ITEM1=Menu.FIRST+1;
	private final static int ITEM2=Menu.FIRST+2;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.five_game_view);
        gameView = (Chessboard) findViewById(R.id.snake);
        gameView.setTextView((TextView)findViewById(R.id.text));
    }
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		//第一个参数：组ID 　第二个参数：菜单项ID　第三个参数：顺序号　第四个参数：菜单项上显示的内容
		menu.add(0,ITEM0,0,"人机");
		menu.add(0,ITEM1,0,"人人");
		menu.add(0,ITEM2,0,"停止");
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case ITEM0:
			// 人机对战
			gameView.startGame(1);
			setTitle("五子棋-人机对战");
			break;
		case ITEM1:
			// 人人对战
			gameView.startGame(2);
			setTitle("五子棋-人人对战");
			break;
		case ITEM2:
			// 重新开始
			gameView.startGame(3);
			setTitle("五子棋");
			break;
		default:
			break;
		}
		return true;
	}
}